
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate";
import { User } from '@/api'
Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		isCollapse: false,
		account: {}
	},
	mutations: {
		toggleMenu(state) {
			state.isCollapse = !state.isCollapse
		},
		setAccount(state, payload) {
			state.account = payload;
		}
	},
	actions: {
		async loadInfo(context, id) {
			//当前账户的id
			let { status, data } = await User.info({ id });
			if (status) {
				context.commit("setAccount", data)
			}
			return { status, data };
		},
		async updateInfo(context, payload) {
			let { status, msg } = await User.edit(payload);
			if (status) {
				context.commit('setAccount', payload)
			}
			return {status,msg};
		}
	},
	modules: {},
	 plugins: [createPersistedState()],
})

